package question;

/**
 * @author zhangxin
 * @date 2021/4/8
 */
public class Demo {

    /**
     * 每瓶啤酒2元，3个空酒瓶或者5个瓶盖可换1瓶啤酒。100元最多可喝多少瓶啤酒？（
     * 不允许借啤酒）思路：利用递归算法，一次性买完，然后递归算出瓶盖和空瓶能换的啤酒数
     *
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(caclu(new A(0, 0, 0), 100));
    }

    public static int caclu(A a, int money) {
        if (money >= 2) {
            return caclu(new A(a.getGai() + 1, a.getPing() + 1, a.getTotalPing() + 1), money - 2);
        }

        if (a.getGai() >= 5) {
            return caclu(new A(a.getGai() - 4, a.getPing() + 1, a.getTotalPing() + 1), money);
        }

        if (a.getPing() >= 3) {
            return caclu(new A(a.getGai() + 1, a.getPing() - 2, a.getTotalPing() + 1), money);
        }

        return a.getTotalPing();
    }


}

class A {

    private int gai;

    private int ping;

    private int totalPing;

    public A() {
    }

    public A(int gai, int ping, int totalPing) {
        this.gai = gai;
        this.ping = ping;
        this.totalPing = totalPing;
    }

    public int getGai() {
        return gai;
    }

    public void setGai(int gai) {
        this.gai = gai;
    }

    public int getPing() {
        return ping;
    }

    public void setPing(int ping) {
        this.ping = ping;
    }

    public int getTotalPing() {
        return totalPing;
    }

    public void setTotalPing(int totalPing) {
        this.totalPing = totalPing;
    }

    @Override
    public String toString() {
        return "A{" +
                "gai=" + gai +
                ", ping=" + ping +
                '}';
    }
}
